import storage from '../storage.js'
const session = "sessionStorage"
export default {
    state: {
        routerHistory: storage.getValue('routerHistory', session) || [],
        nowRouter: storage.getValue('nowRouter', session),
        dict: storage.getValue('dict', session), //数据字典
        baseInfo: storage.getValue('baseInfo', session),
        defaultEquipment: storage.getValue('defaultEquipment', session),
        realMark: storage.getValue('realMark', session),
        signMark: storage.getValue('signMark', session),
    },
    getters: {
        routerHistory: state => state.routerHistory,
    },
    mutations: {
        // 设置数据字典
        setDict(state, dict) {
            state.dict = dict;
            storage.setValue('dict', dict);
        },
        // 清除数据字典
        cleanDict(state) {
            state.dict = undefined;
            storage.cleanValue('dict');
        },
        // 设置路由历史
        setRouterHistory(state, routerHistory) {
            state.routerHistory = routerHistory;
            storage.setValue('routerHistory', routerHistory, session);
        },
        // 清除路由历史
        cleanRouterHistory(state) {
            state.routerHistory = [];
            storage.cleanValue('routerHistory', session);
        },
        // 设置当前路由
        setNowRouter(state, nowRouter) {
            state.nowRouter = nowRouter;
            storage.setValue('nowRouter', nowRouter, session);
        },
        // 清除当前路由
        cleanNowRouter(state) {
            state.nowRouter = undefined;
            storage.cleanValue('nowRouter', session);
        },
        // 设置站点信息
        setBaseInfo(state, baseInfo) {
            state.baseInfo = baseInfo;
            storage.setValue('baseInfo', baseInfo, session);
        },
        // 清除站点信息
        cleanBaseInfo(state) {
            state.baseInfo = undefined;
            storage.cleanValue('baseInfo', session);
        },
        // 设置默认设备
        setDefaultEquipment(state, defaultEquipment) {
            state.defaultEquipment = defaultEquipment;
            storage.setValue('defaultEquipment', defaultEquipment, session);
        },
        // 清除默认设备
        cleanDefaultEquipment(state) {
            state.defaultEquipment = undefined;
            storage.cleanValue('defaultEquipment', session);
        },
        // 设置权益标识
        setRealMark(state, realMark) {
            state.realMark = realMark;
            storage.setValue('realMark', realMark, session);
        },
        // 清除权益标识
        cleanRealMark(state) {
            state.realMark = undefined;
            storage.cleanValue('realMark', session);
        },
        // 设置签到标识
        setSignMark(state, signMark) {
            state.signMark = signMark;
            storage.setValue('signMark', signMark, session);
        },
        // 清除权益标识
        cleanSignMark(state) {
            state.signMark = undefined;
            storage.cleanValue('signMark', session);
        },
    },
    actions: {},
}
